package com.fh.rentcar.service.imp;

import com.fh.rentcar.mapper.OrderMapper;
import com.fh.rentcar.pojo.OrderDetail;
import com.fh.rentcar.pojo.RenewOrder;
import com.fh.rentcar.pojo.dto.OrderCity;
import com.fh.rentcar.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImp implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public int addOrder(OrderDetail order) {
        return orderMapper.addOrder(order);
    }

    @Override
    public void updateOrder(Map<String,Object> orderMap) {
        orderMapper.updateOrder(orderMap);
    }

//    @Override
//    public List<OrderDetail> getAllOrder() {
//        return orderMapper.getAllOrder();
//    }

    @Override
    public List<OrderDetail> getAllOrderWith(Map<String, Object> orderMap) {
        return orderMapper.getAllOrderWith(orderMap);
    }

    @Override
    public int addRenewOrder(RenewOrder orderRenew) {
        return orderMapper.addRenewOrder(orderRenew);
    }

    @Override
    public List<OrderDetail> cityOrderNum(int fg,int status, String cityName) {
        return orderMapper.cityOrderNum(fg,status,cityName);
    }

    /**
     * 各城市订单统计
     */
    @Override
    public List<OrderCity> getCityOrder(){
        String arr[] = {"成都","北京","重庆","广州","深圳"};
        ArrayList<OrderCity> orderCities = new ArrayList<>();
        OrderCity orderCity;
        for(int i = 0; i<arr.length;i++){
            List<OrderDetail> YesOrderDetailList =  orderMapper.cityOrderNum(1,1,arr[i]);//查询预约 完成
            List<OrderDetail> NoOrderDetailList =  orderMapper.cityOrderNum(0,1,arr[i]);//查询退订
            int yes = YesOrderDetailList.size();
            int No = NoOrderDetailList.size();
            orderCity = new OrderCity();
            orderCity.setDealYes(yes);
            orderCity.setDealNo(No);
            orderCity.setCityName(arr[i]);
            System.out.println(arr[i]);
            orderCities.add(orderCity);
        }
        return orderCities;
    }
}
